<script type="text/javascript">
    function TqtjszManagerCtrl($scope, $http, modalService, CtrlUtil, $element, UploadService, $window, $mdSelect,$mdMenu) {
        var ctrl = this
        CtrlUtil.build(ctrl, ':root/tqtjsz/list')
        this.query = function () {
            ctrl.entities && (ctrl.entities.content = {})
            var p = CtrlUtil.getQueryParams(ctrl)
            $http.post(':root/tqtjsz/list', p).success(function (r) {
                ctrl.entities = r;
            })
        }
        this.edit = function (item) {
            ctrl.add(item)
        }
        this.del = function (item) {
            modalService.confirm({
                content: '确定要删除院系' + item.mc + '吗?',
                result: item
            }).then(function (r) {
                $http.post(':root/tqtjsz/delete', r).success(function (R) {
                    modalService.succ('删除成功', 1500)
                    ctrl.query()
                })
            })

        }
        this.batchDel = function(){
            var items = ctrl.getChecked();
            console.log(items);
            if(items && items.length > 0){
                modalService.confirm({
                    content: '确定要删除院系' + items[0][mc]+ '等吗?',
                }).then(function (r) {
                    $http.post(':root/tqtjsz/deleteYxs', items).success(function (R) {
                        modalService.succ('删除成功', 1500)
                        ctrl.query()
                    })
                })
            }
        }
        this.add = function (item) {
            var content = $element.find('[template]>[edit]').clone()
            var title = $element.find('[template]>[edit-title]').clone()
            var result = item,
                result = result || {
                        sfyx: true
                    };

            if (!result.px) {
                $http.post(':root/tqtjsz/px').success(function (r) {
                    result.px = r;
                });
            }

            modalService.confirm({
                title: title,
                content: content,
                size: 'lg',
                titleCls: '',
                result: result,
                $scope: $scope,
                validator: function (r) {

                }
            }, {
                backdrop: false
            }).then(function (r) {
                $http.post(':root/tqtjsz/addYx', r).success(function (R) {
                    modalService.succ(item ? '修改成功' : '添加成功', 1500);
                    ctrl.query();
                })
            })
        }

        $(document).on('click', ".modal-content", function() {
            if($(".md-select-menu-container") && $(".md-select-menu-container").hasClass("md-active")) {
                $mdSelect.hide();
                $mdMenu.hide();
            }
        });
    }

</script>
<div ng-controller="TqtjszManagerCtrl as ctrl" ng-init="ctrl.query()">
    <!-- Search area -->
    <div class="panel panel-cys">
        <div class="panel-heading">
            <h3 class="panel-title">
                <span class="glyphicon glyphicon-search"></span> 信息查询
            </h3>
        </div>
        <div class="panel-body">
            <div class="container-fluid">
                <form class="form-horizontal">
                    <div class="form-group col-md-4 remove-margin-horizontal">
                        <div class="col-md-10 col-md-offset-1">
                            <input placeholder="统计院系名称" ng-model="ctrl.mcQueryParam" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group col-md-4 remove-margin-horizontal">
                        <div class="col-md-10 col-md-offset-1">
                            <select chosen ng-model="ctrl.sfyxQueryParam" class="form-control">
                                <option value="">是否有效</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group col-md-4 remove-margin-horizontal">
                        <div class="col-md-10 col-md-offset-1">
                            <div class="form-control-static">&nbsp;</div>
                        </div>
                    </div>
                </form>
                <div class="row pull-right">
                    <div class="col-md-12">
                        <button ng-click="ctrl.query()" type="submit" class="btn btn-cys btn-sm">
                            <span class="glyphicon glyphicon-search"></span>
                            查询
                        </button>
                        <button ng-click="ctrl.reset()" type="reset" class="btn btn-default btn-sm">
                            <span class="glyphicon glyphicon-repeat"></span>
                            重置
                        </button>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!-- Search area END -->

    <!-- operation area -->
    <a type="button" class="btn btn-cys btn-sm" ng-click="ctrl.add()">
        <span class="glyphicon glyphicon-plus"></span>
        新增
    </a>
    <a type="button" class="btn btn-cys btn-sm" ng-click="ctrl.batchDel()">
        <span class="glyphicon glyphicon-export"></span>
        批量删除
    </a>
    <div class="pull-right" ng-include="':root/components/page.html'"></div>
    <!-- operation area END -->
    <!-- data grid area -->
    <div style="padding-top: 10px;">
        <table class="table table-bordered table-hover table-striped">
            <tr>
                <th>
                    <input ng-change="ctrl.checkAll(ctrl.$checkAll)" ng-model="ctrl.$checkAll" type="checkbox"/>
                </th>
                <th>统计员系名称</th>
                <th>统计院系</th>
                <th>是否有效</th>
                <th>排序</th>
                <th>操作</th>
            </tr>
            <tr ng-repeat="item in ctrl.entities.content">
                <td><input ng-model="item.$checked" type="checkbox"/></td>
                <td>{{item.mc}}</td>
                <td>{{item.bmmc}}</td>
                <td>{{item.sfyx|toBool}}</td>
                <td>{{item.px}}</td>
                <td>
                    <a href="javascript:;" ng-click="ctrl.edit(item)">编辑</a>
                    <a href="javascript:;" ng-click="ctrl.del(item)">删除</a>
                </td>
            </tr>
        </table>
        <p>
            共有记录：
            <span>{{ctrl.entities.totalElements}}</span> 条
        </p>
    </div>
    <!-- data grid area END -->
    <div ng-non-bindable template class="hidden">
        <h3 class="panel-title" edit-title>
            <span class="glyphicon glyphicon-search"></span> 团情统计设置
        </h3>
        <div edit>
            <div class="panel-body">
                <form class="form-horizontal" ng-if="result">
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">统计院系名称:</label>
                            <div class="col-md-4">
                                <input ng-model="result.mc" name="result.mc" placeholder="请输入团组织名称" title="请输入团组织名称"
                                       type="text" class="form-control">
                            </div>
                            <label class="col-md-2 control-label">是否有效:</label>
                            <div class="col-md-4 radio">
                                <input switch-handle-width="80px" bs-switch type="checkbox" ng-model="result.sfyx"
                                       switch-size="small" switch-on-text="是" switch-off-text="否"
                                       name="result.sfyx"/>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">统计院系:</label>
                            <data entity="Bm" auto-load="true" after-refresh="bms=data">
                                <filter field="sfyx" value="1"></filter>
                                <filter field="cc.dm" operator="!=" value="2"></filter>
                            </data>
                            <div class="col-md-4">
                                <md-input-container class="md-block" flex-gt-md>
                                    <md-select  ng-model="result.ssyx" multiple="true" md-auto-hide="true" ng-init="showOptions=true" my-on-focus="showOptions"
                                                md-on-close="showOptions=false">
                                        <md-option ng-repeat="bm in bms" ng-value="bm.id">{{bm.mc}}</md-option>
                                    </md-select>
                                </md-input-container>
                            </div>
                            <label class="col-md-2 control-label">排序:</label>
                            <div class="col-md-4 radio">
                                <input ng-model="result.px" readonly="true" name="result.px"
                                       type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>